﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Wicresoft.IDE.Loader
{
    public class RecentFileUtil
    {
        public static void AddRecentFile(string file)
        {
            var s = GetRecentFiles(0);

            s = s.Except(new string[] { file });
            List<String> list = s.ToList();
            list.Insert(0, file);
            s = list;

            string recentFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                + "\\umc.recent.txt";

            File.WriteAllLines(recentFile,
                s.ToArray(),
                Encoding.UTF8);
        }

        public static IEnumerable<String> GetRecentFiles(int maxLength)
        {
            string recentFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                + "\\umc.recent.txt";

            if (File.Exists(recentFile))
                return File.ReadAllLines(recentFile, Encoding.UTF8);
            else
                return new string[] { };

        }
    }
}
